def Send(ip,command):
    HOST = ip
    PORT = 55555
    BUFSIZ = 4096
    ADDR = (HOST, PORT)
    print(ip)
    tcpClientSock = socket(AF_INET, SOCK_STREAM)
    tcpClientSock.connect(ADDR)
    #tcpClientSock.send(bytes('hi', 'utf-8'))
    str(tcpClientSock.recv(BUFSIZ), encoding='utf-8')
    tcpClientSock.send(bytes(command, 'utf-8'))
    data = str(tcpClientSock.recv(BUFSIZ), encoding='utf-8')
    print(data)
    writeLog(data)
    tcpClientSock.close()

def writeLog(str):
    import time
    year = time.strftime("%Y", time.localtime())
    mon = time.strftime("%m", time.localtime())
    day = time.strftime("%d", time.localtime())
    hour = time.strftime("%H", time.localtime())
    min = time.strftime("%M", time.localtime())
    sec = time.strftime("%S", time.localtime())
    #NowTime = time.strftime('%a %b %d %H:%M:%S %Y')
    f=open(year+mon+day+hour+min+'.log','a')
    f.write(year+'/'+mon+'/'+day+'  '+hour+':'+min+':'+sec+'\n\n'+str+'\n')
    f.close()
#str(year)+str(mon)+str(day)+str(hour)+
if __name__ == '__main__':
    from socket import *
    from time import *
    ip=['172.20.10.5','127.0.0.1']
    print("请选择你需要更新的项目：")
    print("1.官网")
    print("2.代理后台")
    print("3.管理后台")
    print("4.充值中转(暂未启用)")
    print("请输入： 1 2 3 4")
    Num=input("输入你的选择：")
    while True:
        if Num == '1':
            command ='update gw'
            break
        elif Num == '2':
            command='update ag'
            break
        elif Num == '3':
            command = 'update be'
            break
        else:
            print('Error Command')
            Num=input("请再次输入：")
    for i in range(len(ip)):
        Send(str(ip[i]),command)

